var dgram = require("dgram");
var sys = require('sys');
var timer = require('timers');
require('buffer');

var server = dgram.createSocket("udp4");
server.setBroadcast(true);

server.on("message", function(msg, rinfo) {
	console.log("server got: " + msg + " from " + rinfo.address + ":"
			+ rinfo.port);
});

var msg = new Buffer("Discovery: Who is out there?");
server.on('listening', function() {
	timer.setInterval(function() {
		server.send(msg, 0, msg.length, 30303, '255.255.255.255', function(e) {
			sys.puts('Sent broadcast ' + msg.toString());

			if (e) {
				sys.puts(e.message);
				sys.puts(e.stack);
			}

		});
	}, 1000);
});

server.bind(12345,"172.16.1.254");
